package com.agent;

import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

/**
 * 实现 ASM ClassVisitor
 */
public class MonitoringClassVisitor extends ClassVisitor {
    private String className;

    public MonitoringClassVisitor(ClassVisitor cv, String className) {
        super(Opcodes.ASM7, cv);
        this.className = className;
    }

    @Override
    public MethodVisitor visitMethod(int access, String name, String desc,
                                     String signature, String[] exceptions) {
        MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions);
        // 过滤构造函数和静态初始化块
        if (!"<init>".equals(name) && !"<clinit>".equals(name) && mv != null) {
            return new MonitoringMethodVisitor(api, mv, access, name, desc, className);
        }
        return mv;
    }
}